import {Fill, Icon, Style, Text} from "ol/style";

/**
 * overlay-utils
 * overlay 操作相关（显示）
 */
export default {
  data() {
    return {
      selected: null
    }
  },
  methods: {
    /**
     * 标记点弹窗处理
     */
    showMarkerOverlay(options) {
      let {feature} = options
      if (feature.get('type') === 'camera') {
        this.showCameraInfoOverlay(options)
      }
    },
    // 显示人脸报警信息
    showFaceAlarmOverlay(feature) {
      this.map.getOverlays().clear()
      if (!this.$refs.alarmFaceInfoOverlay) {
        return console.log('%c未引入组件！', 'color:red;')
      }
      let coordinate = feature.getGeometry().getCoordinates()
      let AlarmOverlay = this.gisIns.getOverLay('alarmFaceInfoOverlay')
      if (!AlarmOverlay) {
        AlarmOverlay = this.gisIns.addOverLay(this.$refs.alarmFaceInfoOverlay.$el, 'alarmFaceInfoOverlay', {
          autoPan: false, // 定义弹出窗口在边缘点击时候可能不完整 设置自动平移效果
        })
      }
      this.$refs.alarmFaceInfoOverlay.onData({
        self: this,
        feature: feature,
        coordinate: coordinate,
        data: feature.get('data'),
        overlayId: 'alarmFaceInfoOverlay'
      })
      AlarmOverlay.setPosition(coordinate)
      AlarmOverlay.setOffset([0, -50])
    },
    // 车辆报警
    showCarAlarmOverlay(feature) {
      this.map.getOverlays().clear()
      if (!this.$refs.alarmCarInfoOverlay) {
        return console.log('%c未引入组件！', 'color:red;')
      }
      let coordinate = feature.getGeometry().getCoordinates()
      let AlarmOverlay = this.gisIns.getOverLay('alarmCarInfoOverlay')
      if (!AlarmOverlay) {
        AlarmOverlay = this.gisIns.addOverLay(this.$refs.alarmCarInfoOverlay.$el, 'alarmCarInfoOverlay', {
          autoPan: false, // 定义弹出窗口在边缘点击时候可能不完整 设置自动平移效果
        })
      }
      this.$refs.alarmCarInfoOverlay.onData({
        self: this,
        feature: feature,
        coordinate: coordinate,
        data: feature.get('data'),
        overlayId: 'alarmCarInfoOverlay'
      })
      AlarmOverlay.setPosition(coordinate)
      AlarmOverlay.setOffset([0, -55])
    },
    // imsi串码报警
    showImsiAlarmOverlay(feature) {
      this.map.getOverlays().clear()
      if (!this.$refs.alarmImsiInfoOverlay) {
        return console.log('%c未引入组件！', 'color:red;')
      }
      let coordinate = feature.getGeometry().getCoordinates()
      let AlarmOverlay = this.gisIns.getOverLay('alarmImsiInfoOverlay')
      if (!AlarmOverlay) {
        AlarmOverlay = this.gisIns.addOverLay(this.$refs.alarmImsiInfoOverlay.$el, 'alarmImsiInfoOverlay', {
          autoPan: false, // 定义弹出窗口在边缘点击时候可能不完整 设置自动平移效果
        })
      }
      this.$refs.alarmImsiInfoOverlay.onData({
        self: this,
        feature: feature,
        coordinate: coordinate,
        data: feature.get('data'),
        overlayId: 'alarmImsiInfoOverlay'
      })
      AlarmOverlay.setPosition(coordinate)
      AlarmOverlay.setOffset([0, -55])
    },
    /**
     * 摄像机（感知源）
     * @param self
     * @param feature
     * @param {Array} coordinate
     * @param {String} type : list,item
     * @param {Array|Object} data
     */
    showCameraInfoOverlay({self, feature, coordinate, type, data}) {
      this.map.getOverlays().clear()
      if (!this.$refs.cameraInfoOverlay) {
        return console.warn('未引入弹窗组件！')
      }
      let overlay = this.gisIns.getOverLay('cameraInfoOverlay')
      if (!overlay) {
        overlay = this.gisIns.addOverLay(this.$refs.cameraInfoOverlay.$el, 'cameraInfoOverlay', {
          autoPan: false, // 定义弹出窗口在边缘点击时候可能不完整 设置自动平移效果
        })
      }
      this.$refs.cameraInfoOverlay.onData({
        self: this,
        feature: feature,
        coordinate: coordinate,
        data: data,
        type: type,
        overlayId: 'cameraInfoOverlay'
      })
      // overlay.setAutoPan()
      overlay.setPosition(coordinate)
      overlay.setOffset([0, -55])
    },
    /**
     * 根据警员id获取并显示Overlay
     * @param options
     */
    showPoliceInfoOverlayById(options) {
      let {feature, data, type = 'item', layerId = '', layer = ''} = options
      this.map.getOverlays().clear()
      if (!this.$refs.policeOverlay) {
        return console.log('%c未引入组件！', 'color:red;')
      }
      let coordinate = feature.getGeometry().getCoordinates()
      let CustomOverlay = this.gisIns.getOverLay('policeOverlay')
      if (!CustomOverlay) {
        CustomOverlay = this.gisIns.addOverLay(this.$refs.policeOverlay.$el, 'policeOverlay', {
          autoPan: false, // 定义弹出窗口在边缘点击时候可能不完整 设置自动平移效果
        })
      }
      this.$refs.policeOverlay.onData({
        self: this,
        feature: feature,
        coordinate: coordinate,
        type: type,
        data: data,
        overlayId: 'policeOverlay'
      })
      CustomOverlay.setPosition(coordinate)
      CustomOverlay.setOffset([0, -55])
    }
  }
}
